//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "EvolutionDescription.h"
using namespace Cephei::QL::Models::Marketmodels;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription () 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phEvolutionDescription = NULL;
#endif
        _ppEvolutionDescription = new boost::shared_ptr<QuantLib::EvolutionDescription> (new QuantLib::EvolutionDescription ( ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription (boost::shared_ptr<QuantLib::EvolutionDescription>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEvolutionDescription = NULL;
#endif
	_ppEvolutionDescription = &childNative;
    
}
Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription (QuantLib::EvolutionDescription& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phEvolutionDescription = NULL;
#endif
	_ppEvolutionDescription = new boost::shared_ptr<QuantLib::EvolutionDescription> (&childNative);
    
    _EvolutionDescriptionOwner = owner;
    
}

Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription (CEvolutionDescription^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEvolutionDescription = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppEvolutionDescription = new boost::shared_ptr<QuantLib::EvolutionDescription> (copy->GetShared());
        
    }
}
Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEvolutionDescription = NULL;
#endif
	if (!t->IsSubclassOf(CEvolutionDescription::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription (QuantLib::Handle<QuantLib::EvolutionDescription>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phEvolutionDescription = &childNative;
	_ppEvolutionDescription = &static_cast<boost::shared_ptr<QuantLib::EvolutionDescription>>(childNative.currentLink());
    
    _EvolutionDescriptionOwner = owner;
}
Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription (QuantLib::Handle<QuantLib::EvolutionDescription> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phEvolutionDescription = &childNative;
	_ppEvolutionDescription = &static_cast<boost::shared_ptr<QuantLib::EvolutionDescription>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::CEvolutionDescription::CEvolutionDescription (QuantLib::EvolutionDescription childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEvolutionDescription = NULL;
#endif
	_ppEvolutionDescription = new boost::shared_ptr<QuantLib::EvolutionDescription> (new QuantLib::EvolutionDescription (childNative));
    
}
#endif

Cephei::QL::Models::Marketmodels::CEvolutionDescription::~CEvolutionDescription ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppEvolutionDescription != NULL)
    {
	    delete _ppEvolutionDescription;
        _ppEvolutionDescription = NULL;
    }
}
Cephei::QL::Models::Marketmodels::CEvolutionDescription::!CEvolutionDescription ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppEvolutionDescription != NULL)
    {
	    delete _ppEvolutionDescription;
    }
}
QuantLib::EvolutionDescription& Cephei::QL::Models::Marketmodels::CEvolutionDescription::GetReference ()
{
    if (_ppEvolutionDescription == NULL) throw gcnew NativeNullException ();
	return **_ppEvolutionDescription;
}
boost::shared_ptr<QuantLib::EvolutionDescription>& Cephei::QL::Models::Marketmodels::CEvolutionDescription::GetShared ()
{
    if (_ppEvolutionDescription == NULL) throw gcnew NativeNullException ();
	return *_ppEvolutionDescription;
}
QuantLib::EvolutionDescription* Cephei::QL::Models::Marketmodels::CEvolutionDescription::GetPointer ()
{
    if (_ppEvolutionDescription == NULL) throw gcnew NativeNullException ();
	return &**_ppEvolutionDescription;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::EvolutionDescription>& Cephei::QL::Models::Marketmodels::CEvolutionDescription::GetHandle ()
{
	if (_phEvolutionDescription == NULL)
	{
		_phEvolutionDescription = new Handle<QuantLib::EvolutionDescription> (*_ppEvolutionDescription);
	}
	return *_phEvolutionDescription;
}
#endif
bool Cephei::QL::Models::Marketmodels::CEvolutionDescription::HasNative () 
{
	return (_ppEvolutionDescription != NULL);
}

Cephei::IVector<Double>^ Cephei::QL::Models::Marketmodels::CEvolutionDescription::EvolutionTimes::get ()
{
    try
    {
    	std::vector<QuantLib::Time>& _rv = (std::vector<QuantLib::Time>&)(*_ppEvolutionDescription)->evolutionTimes ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<UInt64>^ Cephei::QL::Models::Marketmodels::CEvolutionDescription::FirstAliveRate::get ()
{
    try
    {
    	std::vector<QuantLib::Size>& _rv = (std::vector<QuantLib::Size>&)(*_ppEvolutionDescription)->firstAliveRate ( );   
        Cephei::IVector<UInt64>^ _nrv = gcnew CoVector<UInt64> (gcnew CUInt64Vector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Models::Marketmodels::CEvolutionDescription::NumberOfRates::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppEvolutionDescription)->numberOfRates ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Models::Marketmodels::CEvolutionDescription::NumberOfSteps::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppEvolutionDescription)->numberOfSteps ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Models::Marketmodels::CEvolutionDescription::RateTaus::get ()
{
    try
    {
    	std::vector<QuantLib::Time>& _rv = (std::vector<QuantLib::Time>&)(*_ppEvolutionDescription)->rateTaus ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Models::Marketmodels::CEvolutionDescription::RateTimes::get ()
{
    try
    {
    	std::vector<QuantLib::Time>& _rv = (std::vector<QuantLib::Time>&)(*_ppEvolutionDescription)->rateTimes ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Models::Marketmodels::IEvolutionDescription^ Cephei::QL::Models::Marketmodels::CEvolutionDescription_Factory::Create ()
{
    return gcnew CEvolutionDescription ();
}
